﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="add.aspx.cs" Inherits="background.Manager.Enterprise.Links.add" %>

<!DOCTYPE html>
<% 
    if(string.IsNullOrEmpty(Request["actionType"])) { Response.Write("缺少actionType参数"); return; }
    if(!new Regex("^(add|update)$").IsMatch(Request["actionType"])) { Response.Write("actionType参数：只能是add或update"); return; }
    if(Request["actionType"].ToString()=="update") {
        if(string.IsNullOrEmpty(Request["id"])) { Response.Write("缺少id参数"); return; }
        if(!new Regex("^\\d+$").IsMatch(Request["id"])) { Response.Write("id参数错误"); return; }
    }
%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>编辑友情链接</title>
    <link href="../../Styles/index.css" rel="stylesheet" />
    <script src="../../Scripts/jquery-1.8.2.min.js"></script>
    <script src="../../Scripts/layer/layer.js"></script>

</head>
<body>
    <div class="top">
        <strong>编辑友情链接</strong>
        <span style="float: right"><a href="javascript:history.back();">
            <img src="../../Images/bak.png" />后退</a></span>
    </div>
    <div class="main">
        <!--表单提交-->
        <div>
            <table border="0" cellpadding="0" cellspacing="0" class="table">
                <tr>
                    <th>网站名称</th>
                    <td>
                        <input type="text" id="sitename" class="text" value="" /><i>*</i></td>
                </tr>
                <tr>
                    <th>网站地址</th>
                    <td>
                        <input type="text" id="url" class="text" value="" /><i>空则填“#”</i></td>
                </tr>
                <tr>
                    <th>排序</th>
                    <td>
                        <input type="text" id="order" class="text" value="0" /><i>数字越小排名越靠前</i></td>
                </tr>
                <tr>
                    <td></td>
                    <td>
                        <input type="button" class="sbtn" value="保存" onclick="p.addLink()" /></td>
                </tr>
            </table>
        </div>
    </div>
    <script type="text/javascript">
        var p = {
            addLink: function () {
                var _name = $("#sitename"),
                    _url = $("#url"),
                    _order = $("#order");
                if (_name.val().length == 0) { layer.msg("请输入网站名称"); _name.focus(); return; }
                if (!/^\d+$/.test(_order.val())) { layer.msg("排序只能输入数字"); _order.focus(); return; }
                var data = {
                    action: "<%=Request["actionType"]%>", name: _name.val(), url: _url.val(), order: _order.val()
                }
                if ('<%=Request["actionType"]%>' == 'update') {
                    data["id"] = '<%=Request["id"]%>';
                }
                $.post("Action/Links.ashx", data, function (ret) {
                    if (ret) {
                        layer.msg("恭喜您保存成功", { icon: 1, time: 2000 }, function () { window.location.href = "list.aspx"; })
                    } else {
                        layer.msg("对不起保存失败", { icon: 2, time: 2000 })
                    }
                })
            },
            loadData: function () {
                $.getJSON("Action/Links.ashx", { action: "getInfo", id: '<%=Request["id"]%>' }, function (resultJson) {
                    var json = resultJson[0];
                    $("#sitename").val(json.Name);
                    $("#url").val(json.Url);
                    $("#order").val(json.Order);
                })
            }
        }
        <%=string.IsNullOrEmpty(Request["id"])?"":"p.loadData();"%>
    </script>
    <!--#include file='../../Include/footer.html'-->
</body>
</html>
